package jvm.demo001;

import com.sun.nio.zipfs.ZipFileSystemProvider;
import sun.misc.Launcher;
import sun.misc.URLClassPath;

import java.net.URL;
import java.security.Provider;

public class ClassLoaderTest {

    public static void main(String[] args) {
        System.out.println("****************启动类加载器****************");
        // 获取BootstrapClassLoader能够加载的api路径
        URLClassPath bootstrapClassPath = Launcher.getBootstrapClassPath();
        URL[] urls = bootstrapClassPath.getURLs();
        for (URL url : urls) {
            System.out.println(url.getPath() + "--------->" + url.toExternalForm());
        }
        // 从上面路径中随意选择一个类，来看看它的类加载器是什么：引导类加载器
        ClassLoader classLoader = Provider.class.getClassLoader();
        System.out.println(classLoader);//null，引导类加载器不属于Java语言编写，因此看不到该对象

        System.out.println("****************扩展类加载器****************");
        String property = System.getProperty("java.ext.dirs");
        System.out.println(property);
        for (String s : property.split(";")) {
            System.out.println(s);
        }
        // 从上面路径中随意选择一个类，来看看它的类加载器是什么：扩展类加载器
        ClassLoader classLoader1 = ZipFileSystemProvider.class.getClassLoader();
        System.out.println(classLoader1);//sun.misc.Launcher$ExtClassLoader@4edde6e5

    }
}
